﻿$.post('ghType',function(list){
	$.each(list,function(){
		var opts=$("<option value="+this.tId+">"+this.tName+"</option>");
		$("#select1").append(opts);
	})
},'json');
$.post('keshi',function(list){
	$.each(list,function(){
		var opts=$("<option value="+this.kid+">"+this.kName+"</option>");
		$("#select2").append(opts);
	})
},'json');

$(".panel-footer #ok").off("click").on("click",function(){
	var params=$("#myForm").serialize();//获取所有的子元素
	$.post('addGH',params,function(msg){
		if(msg=="success"){
			swal({  
		           text: "挂号成功",  
		           type: "success",  
		           confirmButtonText: '确认', 
		           confirmButtonColor: '#f8bb86',  
		      });
		}
	});
});
$(".panel-footer #cancel").off("click").on("click",function(){
	swal({  
        text: "确认取消吗？",  
        type: "warning",  
        confirmButtonText: '确认', 
        confirmButtonColor: '#f8bb86',  
   }).then(function(isConfirm){
 	  if (isConfirm == true) {
 		 window.parent.location.href='main';
 	  }
   });
});

function doPrint(){  
	   bindData(); 
	
	   //备份body  
	   var body = window.document.body.innerHTML;  
	   //备份title  
	   var title = document.getElementsByTagName('title')[0].innerHTML;  
	   //获取要打印的内容  
	   var form = $("#myForm").html();  
	     
	   window.document.body.innerHTML = form;  
	   document.getElementsByTagName('title')[0].innerHTML = '';  
	      
	   //调用window的打印功能  
	   window.print();  
	     
	   //恢复原内容  
	   window.document.body.innerHTML = body;  
	   document.getElementsByTagName('title')[0].innerHTML = title;  
	}  
//将表单中手动填写的数据进行绑定，便于html()的时候获取到  
function bindData(){  
    //搞定 type=text, 同时如果checkbox,radio,select>option的值有变化, 也绑定一下, 这里忽略button  
    $("input,select option").each(function(){  
        $(this).attr('value',$(this).val());  
    });  
      
    //搞定 type=checkbox,type=radio 选中状态  
    $("input[type='checkbox'],input[type='radio']").each(function(){  
        if($(this).attr('checked'))  
            $(this).attr('checked',true);  
        else  
            $(this).removeAttr('checked');  
    });  
      
    //搞定select选中状态  
    $("select option").each(function(){  
        if($(this).attr('selected'))  
            $(this).attr('selected',true);  
        else  
            $(this).removeAttr('selected');  
    });  
      
    //搞定 textarea  
    $("textarea").each(function(){  
        $(this).html($(this).val());  
    });  
      
} 

function fmtOpts(){
	var show="<a class='show text-center' href='javascript:void(0)' title='预览交易详情'><i class='glyphicon glyphicon-list-alt'></i>&nbsp;&nbsp;预览交易详情</a>";
	return show;
}

function showInfo(){
	
}
$(document).ready(function(){
	
});
$(".btn1 .btn").off("click").on("click",function(){
	$("#form1").removeClass("dis").addClass("blo");
	$("#grant1").dialog({
		title:"新办一卡通",
		btnName:"提交",
		btnBind:function(){
			var params=$("#form1").serialize();
			//序列化表单值，创建URL编码文本字符串，我们就可以把序列化的值传给ajax()作为url的参数，轻松使用ajax()提交form表单了，而不需要一个一个获取表单中的值然后传给ajax()
			$.post("addYC",params,function(msg){
				if(msg=="success"){
					$("#grant1").dialog("close")
					swal({  
				           text: "新办一卡通成功",  
				           type: "success",  
				           confirmButtonText: '确认', 
				           confirmButtonColor: '#f8bb86',  
				      }).then(function(isConfirm){
				    	  if (isConfirm == true) {
				    		  location="yiCardJsp";
				    	  }
				      });
				}
			});
		}
	});
	$("#grant1").dialog("open");
});
$(".btn2 .btn").off("click").on("click",function(){
	var rows=$("#myTable").bootstrapTable("getSelections");
	if(rows.length==0){
		swal({  
            text: "请选择一项待退办!",  
            type: "warning",  
            confirmButtonText: '确认', 
            confirmButtonColor: '#f8bb86',  
        });
		return;
	}
	$("#yId2").val(rows[0].yId);
	$("#uName2").val(rows[0].yiCardUser.uName);
	$("#yMoney2").val(rows[0].yMoney);
	$("#uCard2").val(rows[0].yiCardUser.uCard);
	$("#state2").val('0');
	
	$("#form2").removeClass("dis").addClass("blo");
	$("#grant2").dialog({
		title:"退办一卡通",
		btnName:"提交",
		btnBind:function(){
			var params=$("#form2").serialize();
			$.post("backYC",params,function(msg){
				if(msg=="success"){
					$("#grant2").dialog("close")
					swal({  
				           text: "退办一卡通成功",  
				           type: "success",  
				           confirmButtonText: '确认', 
				           confirmButtonColor: '#f8bb86',  
				      }).then(function(isConfirm){
				    	  if (isConfirm == true) {
				    		  location="yiCardJsp";
				    	  }
				      });
				}
			});
		}
	});
	$("#grant2").dialog("open");
});
$(".btn3 .btn").off("click").on("click",function(){
	var rows=$("#myTable").bootstrapTable("getSelections");
	if(rows.length==0){
		swal({  
            text: "请选择一项待充值!",  
            type: "warning",  
            confirmButtonText: '确认', 
            confirmButtonColor: '#f8bb86',  
        });
		return;
	}
	
	$("#yId3").val(rows[0].yId);
	$("#uName3").val(rows[0].yiCardUser.uName);
	$("#yMoney3").val(rows[0].yMoney);
	
	$("#form3").removeClass("dis").addClass("blo");
	$("#grant3").dialog({
		title:"一卡通充值",
		btnName:"提交",
		btnBind:function(){
			var params=$("#form3").serialize();
			$.post("chongMoney",params,function(msg){
				if(msg=="success"){
					$("#grant3").dialog("close")
					swal({  
				           text: "充值一卡通成功",  
				           type: "success",  
				           confirmButtonText: '确认', 
				           confirmButtonColor: '#f8bb86',  
				      }).then(function(isConfirm){
				    	  if (isConfirm == true) {
				    		  location="yiCardJsp";
				    	  }
				      });
				}
			});
		}
	});
	$("#grant3").dialog("open");
});

function search(){
    var param={};
    param.columnName=$("#condition").find("[name=columnName]").val();
    param.columnValue=$("#condition").find("[name=columnValue]").val();
    $("#myTable").bootstrapTable("refresh",{query:param});
}
function searchGuaHao(){
    var param={};
    param.columnName=$("#condition").find("[name=columnName]").val();
    param.columnValue=$("#condition").find("[name=columnValue]").val();
    $("#ghTable").bootstrapTable("refresh",{query:param});
}
function searchUser(){
    var param={};
    param.columnName=$("#condition").find("[name=columnName]").val();
    param.columnValue=$("#condition").find("[name=columnValue]").val();
    $("#Table").bootstrapTable("refresh",{query:param});
}
function fmtOpt(){
	var show="<a class='show text-center' href='javascript:void(0)' title='预览交易详情'><i class='glyphicon glyphicon-list-alt'></i>&nbsp;&nbsp;预览交易详情</a>";
}
